package com.travel.Controller;

import com.travel.Bean.Manager;
import com.travel.Service.Impl.ManagerServiceImpl;
import com.travel.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/Admin")
@Api(value = "管理员相关接口")
public class AdminLoginController {

    @Autowired
    private ManagerServiceImpl managerService;


    //获取管理员权限信息
    public String getAdminRole() {
        String role;
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof UserDetails) {
            role = ((UserDetails) principal).getAuthorities().toString();
        } else {
            role = principal.toString();
        }
        return role;
    }



    @ApiOperation(value = "管理员信息接口")
    @RequestMapping("/adminInfo")
    @ResponseBody
    public R adminLogin(String username){
        Manager manager = managerService.findManagerByUsername(username);
        return R.ok(0,manager.toString());
    }





/*
    @RequestMapping("/AdminLogin")
    @ResponseBody
    public R AdminLogin(String username,String password){

    }
*/


}
